package com.question.java.util;


import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * @Description:
 * @Author: Jun Yang
 * @Time: 2018/10/21 下午8:49
 * @Version: 1.0
 */
public class UtilityClass {

    private static DecimalFormat df = new DecimalFormat("0.00");

    private UtilityClass() {
        throw new AssertionError();
    }

    public static BigDecimal computeMoney(double... moneys) {
        if (moneys == null || moneys.length == 0) return null;

        BigDecimal result = BigDecimal.ZERO;

        for (int i = 0; i < moneys.length; i++) {
            result = result.add(BigDecimal.valueOf(moneys[i]));
        }

        return result;
    }

    public static String formatMoney(double money) {
        return df.format(money);
    }
}
